package Problem.project;
/*
    多线程安全问题：多线程访问了共同的数据（同一个线程任务），会产生线程安全问题

    解决线程安全问题：共三种方法
        1.同步代码块
        2.同步方法
        3.锁机制(lock锁)

 */
public class PracticeMain {
    public static void main(String[] args) {

        //同步代码块
        MyProblem m = new MyProblem();
        //一定是要启动同一个线程任务
        Thread t1 = new Thread(m);
        Thread t2 = new Thread(m);
        Thread t3 = new Thread(m);
        t1.start();
        t2.start();
        t3.start();

        //同步方法
        MyProblem2 n = new MyProblem2();
        Thread n1 = new Thread(n);
        Thread n2 = new Thread(n);
        Thread n3 = new Thread(n);
        n1.start();
        n2.start();
        n3.start();

        //lock锁
        MyProblem3 b = new MyProblem3();
        Thread b1 = new Thread(b);
        Thread b2 = new Thread(b);
        Thread b3 = new Thread(b);
        b1.start();
        b2.start();
        b3.start();
    }
}
